package com.idroid.domain;

import java.io.Serializable;
import java.text.NumberFormat;

public class ParkingArea implements Serializable {

	private static final long serialVersionUID = 7157536283040071272L;
	int id;
	String address;
	String city;
	String state;
	int zipCode;
	float hourlyRate;
	AreaType areaType;
	PaymentMethodType paymentMethod;
	int spacesAvailable;
	int numberOfSpaces;
	private String phoneNumber;
	private String areaName;
	private boolean hasPosition = false;
	private double latitude = 0;
	private double longitude = 0;
	private float distanceFromUserInMiles = Float.MAX_VALUE;

	public ParkingArea(int rampId, String rampName, String addressLine1,
			String city, String state, String zipcode, float amount,
			int capacity, int availability, String area, String payment,
			String phoneNumber, double latitude, double longitude,
			String hasPosition)

	{
		this.id = rampId;
		this.areaName = rampName;
		this.address = addressLine1;
		this.city = city;
		this.state = state;
		this.zipCode = Integer.parseInt(zipcode);
		this.hourlyRate = amount;
		this.numberOfSpaces = capacity;
		this.spacesAvailable = availability;
		this.areaType = AreaType.fromString(area);
		this.paymentMethod = PaymentMethodType.valueOf(payment);
		this.phoneNumber = phoneNumber;
		this.latitude = latitude;
		this.longitude = longitude;
		if (hasPosition != null && hasPosition.length() > 0) {
			this.hasPosition = hasPosition.equals("1") ? true : false;
		}

	}

	public ParkingArea() {

	}

	public ParkingArea(int id, String areaName, String phoneNumber,
			String address, String city, String state, int zipCode,
			float hourlyRate, AreaType areaType,
			PaymentMethodType paymentMethod, int spacesAvailable,
			int numberOfSpaces) {
		super();
		this.id = id;
		this.areaName = areaName;
		this.phoneNumber = phoneNumber;
		this.address = address;
		this.city = city;
		this.state = state;
		this.zipCode = zipCode;
		this.hourlyRate = hourlyRate;
		this.areaType = areaType;

		this.paymentMethod = paymentMethod;
		this.spacesAvailable = spacesAvailable;
		this.numberOfSpaces = numberOfSpaces;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;

	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;

	}

	public String getAreaName() {
		return this.areaName;
	}

	public int getId() {
		return id;
	}

	public String getAddress() {
		return address;
	}

	public boolean getHasPosition() {
		return hasPosition;
	}

	public double getLatitude() {
		return latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setHasPosition(boolean hasPosition) {
		this.hasPosition = hasPosition;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public String getCity() {
		return city;
	}

	public String getState() {
		return state;
	}

	public int getZipCode() {
		return zipCode;
	}

	public float getHourlyRate() {
		return hourlyRate;
	}

	public AreaType getAreaType() {
		return areaType;
	}

	public PaymentMethodType getPaymentMethod() {
		return paymentMethod;
	}

	public int getSpacesAvailable() {
		return spacesAvailable;
	}

	public int getNumberOfSpaces() {
		return numberOfSpaces;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public void setState(String state) {
		this.state = state;
	}

	public void setZipCode(int zipCode) {
		this.zipCode = zipCode;
	}

	public void setHourlyRate(float hourlyRate) {
		this.hourlyRate = hourlyRate;
	}

	public void setAreaType(AreaType areaType) {
		this.areaType = areaType;
	}

	public void setPaymentMethod(PaymentMethodType paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	public void setSpacesAvailable(int spacesAvailable) {
		this.spacesAvailable = spacesAvailable;
	}

	public void setNumberOfSpaces(int numberOfSpaces) {
		this.numberOfSpaces = numberOfSpaces;
	}

	public String toString() {
		return address + " (" + hourlyRate + ")";
	}

	public float getDistanceFromUserInMiles() {
		return distanceFromUserInMiles;
	}

	public void setDistanceFromUserInMiles(float distanceFromUserInMiles) {
		this.distanceFromUserInMiles = distanceFromUserInMiles;
	}

	public String getFormattedHourlyRate() {

		NumberFormat fmt = NumberFormat.getCurrencyInstance();
		return fmt.format(hourlyRate);

	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ParkingArea other = (ParkingArea) obj;
		if (id != other.id)
			return false;
		return true;
	}

}
